home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / TGCBOR20.ARJ / INTROPAK.COM / SLIDER.C < prev    next >
C/C++ Source or Header  |  1991-08-14  |  3KB  |  85 lines

  1.   /* --------------------------------------------------------- */
  2.   /*  Demonstrates how to place a slider in a frame.           */
  3.   /* --------------------------------------------------------- */
  4.  
  5.  
  6. #include "teglsys.h"
  7.  
  8. imagestkptr  ifs;
  9. sliderptr    sldptr;
  10.  
  11.   /* -- slideaction is called whenever the slider is moved  */
  12.  
  13.  
  14. unsigned slideaction(imagestkptr  ifs, msclickptr   ms)
  15.   { unsigned long      dx, dy;   /* -- delta  */
  16.     char s[20];
  17.  
  18.     getsliderrelative(sldptr,100l,&dx,0l,&dy);   /* -- ignore y  */
  19.     setviewport(ifs->x + 1,ifs->y + 60,ifs->x1 - 1,ifs->y1 - 1,TRUE);
  20.  
  21.       /* -- clear lower part of frame  */
  22.     prepareforupdate(ifs);
  23.     setfillstyle(SOLID_FILL,WHITE);
  24.     bar(0,0,1000,1000);   /* -- let clip do the work  */
  25.     outtextxy(10,10,itoa(dx,s,10));
  26.     setviewport(0,0,getmaxx(),getmaxy(),FALSE);   /* -- restore to full screen  */
  27.     commitupdate();
  28.     return 0;
  29.   }
  30.  
  31.  
  32. void         framewithslider(void)
  33.   {
  34.       /* -- push an image an save the frame pointer, then clear it */
  35.     pushimage(10,10,310,190);
  36.     ifs = stackptr;
  37.  
  38.       /* -- set the viewport over the frame so bar and rectangle will  */
  39.       /* -- be relative to the frame  */
  40.     setviewport(10,10,310,190,FALSE);
  41.     setfillstyle(SOLID_FILL,WHITE);
  42.     bar(0,0,300,180);
  43.     setcolor(BLACK);
  44.     rectangle(0,0,300,180);
  45.     setfillstyle(SOLID_FILL,LIGHTGRAY);
  46.     bar(50,0,200,20);
  47.     setcolor(BLACK);
  48.     rectangle(50,0,200,20);
  49.  
  50.       /* -- definesliderarea is FRAME RELATIVE, the first 4 coordinates define  */
  51.       /* -- the slider thumb (the moveable part) and the second 4 coordinates  */
  52.       /* -- define the entire slider area (its scope)  */
  53.       /* -- slider thumb  */
  54.       /* -- slider bar  */
  55.       definesliderarea(ifs,50,0,100,20,50,0,200,20,slideaction);   /* -- event to calll when moved  */
  56.  
  57.       /* -- save the slider pointer  */
  58.     sldptr = getlastsliderdef(ifs);
  59.  
  60.       /* -- only AFTER drawing the slider then defining it do we draw the  */
  61.       /* -- thumb. During define is when the slider captures the screen image */
  62.       /* -- of the slider area.  */
  63.  
  64.     setfillstyle(SOLID_FILL,RED);
  65.     bar(50,0,100,20);   /* -- note same coordiantes as slider thumb above.  */
  66.     setcolor(BLACK);
  67.     rectangle(50,0,100,20);
  68.     putpict(ifs->x + 65,ifs->y + 5,imageSLIDER2,BLACK);
  69.     setviewport(0,0,getmaxx(),getmaxy(),FALSE);   /* --restore viewport  */
  70.   }
  71.  
  72.  
  73. void main(int argc, char **argv)
  74. {
  75.  
  76.  
  77.   easytegl();
  78.   easyout();
  79.   framewithslider();
  80.   teglsupervisor();
  81. }
  82.  
  83.  
  84.  
  85.